<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>贪吃蛇游戏</title>
    <style>
        body {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
            font-family: Arial, sans-serif;
        }
        canvas {
            border: 2px solid #333;
            background-color: #fff;
        }
        .score-container {
            display: flex;
            gap: 20px;
            margin-bottom: 20px;
        }
        .score, .high-score {
            font-size: 24px;
        }
        .game-over {
            display: none;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: rgba(0, 0, 0, 0.8);
            color: white;
            padding: 20px;
            border-radius: 10px;
            text-align: center;
        }
        button {
            padding: 10px 20px;
            font-size: 16px;
            cursor: pointer;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 5px;
            margin-top: 10px;
        }
        button:hover {
            background-color: #45a049;
        }
        .instructions {
            margin-top: 20px;
            text-align: center;
            color: #666;
        }
        .food-legend {
            display: flex;
            gap: 15px;
            margin-top: 10px;
        }
        .food-item {
            display: flex;
            align-items: center;
            gap: 5px;
        }
        .food-color {
            width: 15px;
            height: 15px;
            border: 1px solid #333;
        }
    </style>
</head>
<body>
    <div class="score-container">
        <div class="score">分数: <span id="score">0</span></div>
        <div class="high-score">最高分: <span id="highScore">0</span></div>
    </div>
    <canvas id="gameCanvas" width="400" height="400"></canvas>
    <div class="instructions">
        <p>使用方向键控制蛇的移动</p>
        <div class="food-legend">
            <div class="food-item">
                <div class="food-color" style="background-color: red;"></div>
                <span>普通食物 (+10分)</span>
            </div>
            <div class="food-item">
                <div class="food-color" style="background-color: gold;"></div>
                <span>特殊食物 (+30分)</span>
            </div>
            <div class="food-item">
                <div class="food-color" style="background-color: purple;"></div>
                <span>超级食物 (+50分)</span>
            </div>
        </div>
    </div>
    <div class="game-over" id="gameOver">
        <h2>游戏结束!</h2>
        <p>最终分数: <span id="finalScore">0</span></p>
        <p>最高分: <span id="highScoreModal">0</span></p>
        <button onclick="restartGame()">重新开始</button>
    </div>
    <script src="game.js"></script>
</body>
</html> 